package com.edu.vo;

import com.baomidou.mybatisplus.extension.api.R;
import lombok.Data;
import org.springframework.util.StringUtils;

/**
 * @ClassName Result
 * @Description
 * @Author W.Jian
 * @Date 2021/5/22 14:33
 **/
@Data
public class Result<T> {
    private String code;
    private String message;
    private T data;
    private long count;



    public static <T> Result<T> build(){
        return new Result<T>();
    }

    public Boolean isSuccess(){
        return this.getCode().equals("200");
    }

    public static <T> Result<T> success(){
        Result result = build();
        result.setCode("200");
        result.setMessage("成功");
        return result;
    }

    public static <T> Result<T> success(T data,long count){
        Result result = success();
        result.setData(data);
        result.setCount(count);
        return result;
    }

    public static <T> Result<T> success(T data){
        Result result = success();
        result.setData(data);
        return result;
    }

    public static <T> Result<T> failure(){
        Result result = build();
        result.setCode("500");
        result.setMessage("失败");
        return result;
    }

    public static <T> Result<T> failure(String code,String message){
        Result result = failure();
        if(!StringUtils.isEmpty(code)){
            result.setCode(code);
        }
        if(!StringUtils.isEmpty(message)){
            result.setMessage(message);
        }
        return result;
    }

}
